package com.glela.ningchongqing;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;

import com.alibaba.fastjson.JSONObject;
import com.glela.common.util.HttpUtil;
import com.glela.common.util.JsonUtil;
import com.glela.goods.model.vo.goods.GoodsVo;
import com.google.gson.Gson;

public class 双11活动测试 {
//	public final static String url = "http://api.xzhuang.com/v2/yg_platform/";
//	public final static String url = "http://api.test.xzhuang.com/yg_platform/";
	public final static String url = "http://api.dev.xzhuang.com/yg_platform/";
//	public final static String url = "http://localhost:8080/yg_platform/";

	public static void main(String[] args) throws Exception {
//		goToSettleAccounts();
//		storeGoodsList(1,10);
//		productInfo();
//		popover();
//		activityInfo();// 预加载双11活动信息
		homePage();
//		activePage();
	}
	
	/** 查询店主精选产品  */
	public static void goToSettleAccounts() {
		JSONObject jo = new JSONObject();
//		jo.put("userId", 1475);
		jo.put("orderSn", "P151003711949262525");
		jo.put("payType", "23");
		try {
			String post = HttpUtil.doPost(jo.toJSONString(), url + "orderPay/goToSettleAccounts","application/json");
			System.out.println("goToSettleAccounts========"+post);
		} catch (Exception e) {
			System.out.println("goToSettleAccounts-------------------"+e.getMessage());
		}
	}
	
	/** 查询店主精选产品  */
	public static void storeGoodsList(Integer page,Integer pageSize) {
		JSONObject jo = new JSONObject();
		jo.put("userId", 1475);
//		jo.put("froms", 519);
		jo.put("pageNum", page);
		jo.put("pageSize", pageSize);
		try {
			String post = HttpUtil.doPost(jo.toJSONString(), url + "storeGoods/getStoreGoodsList","application/json");
			System.out.println("storeGoodsList========"+post);
		} catch (Exception e) {
			System.out.println("storeGoodsList-------------------"+e.getMessage());
		}
	}
	
	/** 产品详情  */
	public static void goodsInfo() {
		// 1475-2462-3040-0-0
		// storeUserId + "-" + goodsid + "-" + productId + "-" + limitTimeSaleId + "-" + shareGoodsId;
		//GENERAL-506-539-251-0 
		JSONObject jo = new JSONObject();
		jo.put("userId", 1475);
		jo.put("goodId", 506);
		jo.put("productId", 539);
		jo.put("limitTimeSaleId", 251);
		try {
			String post = doPost(jo.toJSONString(), url + "goods/getGoodsInfoById","application/json");
			System.out.println("goodsInfo========"+post);
		} catch (Exception e) {
			System.out.println("goodsInfo----------异常---------"+e.getMessage());
		}
	}
	
	public static String doPost(String content,String url,String contentType) throws IOException {
		StringBuilder result = new StringBuilder();
        URL postUrl = new URL(url);  
        URLConnection con = postUrl.openConnection(); 
        con.setConnectTimeout(5000);
        con.setDoOutput(true);  
        con.setRequestProperty("Pragma", "no-cache");  
        con.setRequestProperty("Cache-Control", "no-cache"); 
        if(contentType!=null)
        {
        	con.setRequestProperty("Content-Type", contentType);  
        }
        OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());    
        out.write(new String(content.getBytes("UTF-8")));  
        out.flush();  
        out.close();  
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));  
        String line = "";  
        for (line = br.readLine(); line != null; line = br.readLine()) {  
        	result = result.append(line);
        }  
		return result.toString();
	}
	
	/** 规格  */
	public static void productInfo() {
		JSONObject jo = new JSONObject();
//		jo.put("userId", "1475");
//		jo.put("goodId", 81);
//		jo.put("specInfo", "43|162"); 
		jo.put("userId", "277");
		jo.put("goodId", 507);
		jo.put("specInfo", "43|154");  
		try {
			String post = HttpUtil.doPost(jo.toJSONString(), url + "product/getProductInfoByGoodIdAndSpecInfo","application/json");
			System.out.println("productInfo========"+post);
		} catch (Exception e) {
			System.out.println("productInfo-------------------"+e.getMessage());
		}
	}
	
	public static void popover() {
		JSONObject jo = new JSONObject();
		jo.put("goodsId", "717");
		try {
			String post = HttpUtil.doPost(jo.toJSONString(), url + "activities/popover","application/json");
			System.out.println("popover========"+post);
		} catch (Exception e) {
			System.out.println("popover----------异常---------"+e.getMessage());
		}
	}
	
	public static void activityInfo() {
		JSONObject jo = new JSONObject();
		try {
			String post = HttpUtil.doPost(jo.toJSONString(),url + "preload/loadActivityInfo","application/json");
			System.out.println("activityInfo========"+post);
		} catch (Exception e) {
			System.out.println("activityInfo----------异常---------"+e.getMessage());
		}
	}
	
	public static void homePage() {
		JSONObject jo = new JSONObject();
		try {
			String post = HttpUtil.doPost(jo.toJSONString(),url + "marketingActivities/homePage","application/json");
			System.out.println("homePage========"+post);
		} catch (Exception e) {
			System.out.println("homePage----------异常---------"+e.getMessage());
		}
	} 
	
	public static void activePage() {
		JSONObject jo = new JSONObject();
		jo.put("userId", 0);
		jo.put("marketingActivitiesId", 4);
		try {
			String post = HttpUtil.doPost(jo.toJSONString(),url + "marketingActivities/activePage","application/json");
			System.out.println("activePage========"+post);
		} catch (Exception e) {
			System.out.println("activePage----------异常---------"+e.getMessage());
		}
	}

}
